//
//  LaunchVC.m
//  ImGuider
//
//  Created by llt on 2017/4/10.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "LaunchVC.h"
#import "MainTabBarVC.h"
#import "AppIntroduceVC.h"

@interface LaunchVC ()

@property (nonatomic) BOOL annimationHasLoad;

@property (weak, nonatomic) IBOutlet UIImageView *mainBG;

@property (weak, nonatomic) IBOutlet UIImageView *logoBG;
@property (weak, nonatomic) IBOutlet UIImageView *logo2BG;
@property (weak, nonatomic) IBOutlet UILabel *sloganLabel;

@property (nonatomic) CGFloat lastScale;

@end

@implementation LaunchVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)setupUI {
    
    self.sloganLabel.text = MYLocalizedString(@"LAUNCH_INVALIDNAME", nil);
    self.logo2BG.image = [UIImage imageNamed:MYLocalizedString(@"LAUNCH_OPEN", nil)];
    
    self.lastScale = 1.0;
    
    @weakify(self);
    [NSTimer scheduledTimerWithTimeInterval:4.0f block:^(NSTimer * _Nonnull timer) {
        
        @strongify(self);
        
        [self scaleImageAction];
        
    } repeats:YES];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self gotoMain];
    });
    
    self.mainBG.alpha = 0;
    [UIView animateWithDuration:2.0f animations:^{
        @strongify(self);
        self.mainBG.alpha = 1;
    }];
}

- (BOOL)prefersStatusBarHidden {
    
    return YES;
}

- (void)scaleImageAction {
    
    self.mainBG.transform = CGAffineTransformMakeScale(self.lastScale, self.lastScale);
    self.lastScale += 0.0004;
    
    if (self.lastScale > 2) {
        self.lastScale = 2;
    }
}

- (void)gotoMain {
    
    BOOL hasInApp = [[NSUserDefaults standardUserDefaults] boolForKey:@"hasInApp"];
    
    if (!hasInApp) {
        
        AppIntroduceVC *vc = [AppIntroduceVC new];
        [UIApplication sharedApplication].keyWindow.rootViewController = vc;
        
        return;
    }
    
    MainTabBarVC *tabVC = [MainTabBarVC new];

    [UIApplication sharedApplication].keyWindow.rootViewController = tabVC;
}

@end

